# -*- coding: utf-8 -*-
import os
import sys
import requests
import re
from lxml import etree
import string
from openpyxl import workbook # 写入Excel表所用
from openpyxl import load_workbook # 读取Excel表所用
from bs4 import BeautifulSoup 
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from fontTools.ttLib import TTFont
def main():
    title_list = []
    price_list = []
 
    chrome_options = Options()
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('–blink-settings=imagesEnabled=false')
    chrome_options.add_argument('User-Agen =  "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36"')
    chrome_options.add_argument('referer= "https://km.58.com/kmgaoxin/zufang/j1/?PGTID=0d300008-0021-fbf5-3f54-773bfb0fecb0&ClickID=2"')
    browser = webdriver.Chrome(chrome_options=chrome_options)                   
    browser.get("https://km.58.com/kmgaoxin/zufang/j1/?PGTID=0d300008-02f1-73d5-3531-e187470fda1e&ClickID=2")
    soup = BeautifulSoup(browser.page_source,"lxml")
    title = soup.find_all("a",class_="strongbox")    
    for i in title:
        title_list.append(i.string)
    price = soup.find_all("b",class_="strongbox")
    for a in price:
        price_list.append(a.string)
    for num in range(len(title_list)):
        ws.append([title_list[num],price_list[num]])

if __name__ == '__main__': 
    font_parse = TTFont("font_new.ttf")
    font_parse.saveXML('font_parse_2.xml')
    global ws,wb
    main()    
    